package com.lanxin.oa.message.controller;

import com.lanxin.bean.XxDuanxiaoxi;
import com.lanxin.bean.XxXiaoxijieshou;
import com.lanxin.bean.ZzAccount;
import com.lanxin.oa.message.service.DuanxiaoxiService;
import com.lanxin.util.PageBean;
import com.lanxin.util.TimeConverter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

@Controller
@RequestMapping("duanxiaoxi")
public class DuanxiaoxiController extends TimeConverter {

    @Autowired
    private DuanxiaoxiService duanxiaoxiService;

    //查询联系人
    @RequestMapping("listDuanxiaoxi")
    public ModelAndView listDuanxiaoxi(Integer page, Integer pageSize, HttpSession session) {
        ZzAccount account = (ZzAccount) session.getAttribute("account");
        PageBean<XxDuanxiaoxi> duanxiaoxiList = duanxiaoxiService.listDuanxiaoxi(page, pageSize, account.getEmployee().getOid());
        ModelAndView mv = new ModelAndView();
        mv.addObject("duanxiaoxiList", duanxiaoxiList);
        mv.setViewName("../view/xx/listDuanxiaoxi.jsp");
        return mv;
    }

    //发送联系人
    @RequestMapping("sendDuanxiaoxi")
    public ModelAndView sendDuanxiaoxi(HttpServletRequest request, XxDuanxiaoxi duanxiaoxi,
                                       Integer[] empids, MultipartFile[] file) {
        duanxiaoxiService.insertDuanxiaoxi(request, duanxiaoxi, empids, file);
        System.out.println(empids[0]);
        ModelAndView mv = new ModelAndView();
        mv.setViewName("redirect:listDuanxiaoxi");
        return mv;
    }

    //通过接收人查询
    @RequestMapping("xxjsList")
    public ModelAndView xxjsList(Integer page, Integer pageSize, HttpSession session) {
        ZzAccount account = (ZzAccount) session.getAttribute("account");
        PageBean<XxXiaoxijieshou> xxjsPage = duanxiaoxiService.xxjsList(page, pageSize, account.getEmployee().getOid());
        ModelAndView mv = new ModelAndView();
        mv.addObject("xxjsPage", xxjsPage);
        mv.setViewName("../view/xx/xiaoxijieshou.jsp");
        return mv;
    }

    //查看详情
    @RequestMapping("xxjsxq")
    public ModelAndView xxjsxq(Integer oid) {
        XxXiaoxijieshou xxjs = duanxiaoxiService.xxjsxq(oid);
        ModelAndView mv = new ModelAndView();
        mv.addObject("xxjs", xxjs);
        mv.setViewName("../view/xx/xxjisxq.jsp");
        return mv;
    }

    //调用下载
    @RequestMapping("xiazai")
    public void xiazai(String fileName, HttpServletResponse response, HttpServletRequest request) {
        System.out.println("fileName: " + fileName);
        if (fileName != null && !fileName.equals("")) {
            duanxiaoxiService.xiazaifiles(fileName, response, request);
        }
    }

}
